package com.jarvis.du.baselibrary.cookie;

import java.io.Serializable;
import java.util.Comparator;

import okhttp3.Cookie;

/**
 * Author: dyj
 * Date: 2018/8/22 下午3:13
 * E-mail: duyangjun1991@163.com
 */

public class CookieIdentityComparator implements Serializable, Comparator<Cookie> {

    public CookieIdentityComparator() {
    }

    @Override
    public int compare(Cookie o1, Cookie o2) {
        int res = o1.name().compareTo(o2.name());
        if (res == 0) {
            String d1 = o1.domain();
            if (d1 == null) {
                d1 = "";
            }

            String d2 = o2.domain();
            if (d2 == null) {
                d2 = "";
            }

            res = d1.compareToIgnoreCase(d2);
        }

        return res;
    }
}
